package com.example.administrator.atfragment.utils;

import android.content.res.Resources;
import android.graphics.Paint;
import android.support.annotation.DimenRes;


/**
 * 文本工具类
 * Created by baron
 * Date : 2016/5/10 0010 11:13
 * Email: 5267621@qq.com
 */
public class TextFontUtils {

    /**
     * 获取TextView的实际内容高度
     * <p/>
     * 带字符bottom-ascent
     * <p/>
     * 无字符descent-ascent
     *
     * @param fontSize 文字的尺寸size
     * @return
     */
    public static int getFontHeight(Resources resources, @DimenRes int fontSize) {
        Paint paint = new Paint();
        paint.setTextSize(resources.getDimensionPixelOffset(
                fontSize));
        Paint.FontMetrics fm = paint.getFontMetrics();
        return (int) Math.ceil(fm.descent - fm.ascent);
    }

}
